"""
class txt_tools(object):
    def __init__(self,txt_file):
         self.f2=open(txt_file, 'a', encoding='UTF-8')

    def MakeFolder1(self):
        self.f2.write('<Style id="cqt">'+'\n')
        self.f2.write('<IconStyle>'+'\n')
        self.f2.write('<color>e5ff0000</color><scale>0.8</scale>'+'\n')
        self.f2.write('<Icon><href>http://maps.google.com/mapfiles/kml/shapes/shaded_dot.png</href></Icon>'+'\n')
        self.f2.write('</IconStyle>'+'\n')
        self.f2.write('<LabelStyle><color>e580ffff</color></LabelStyle>'+'\n')
        self.f2.write('</Style>'+'\n')
        self.f2.write('\n')

    def MakeFolder2(self):
        self.f2.write('<Style id="25516776960">'+'\n')
        self.f2.write('<PolyStyle><color>FF00FFFF</color></PolyStyle>'+'\n')
        self.f2.write('<LineStyle><color>FF00FFFF</color><width>3</width></LineStyle>'+'\n')
        self.f2.write('</Style>'+'\n')
        self.f2.write('\n')

    def MakeFolder3(self):
        self.f2.write('<Style id="mycat">'+'\n')
        self.f2.write('<IconStyle>')
        self.f2.write('<color>FF00FFFF</color><scale>1.5</scale>'+'\n')
        self.f2.write('<Icon><href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href></Icon>'+'\n')
        self.f2.write('</IconStyle>'+'\n')
        self.f2.write('<LabelStyle><color>e580ffff</color></LabelStyle>'+'\n')
        self.f2.write('</Style>'+'\n')
        self.f2.write('\n')

    def MakePlacemark1(self,Place1):
        self.f2.write('<Placemark>'+'\n')
        self.f2.write('<name>' + ThisWorkbook.Sheets("拉线图制作").Cells(Place1, 6) + '</name>'+'\n')
        'self.f2.write ('<name>' + Str(ThisWorkbook.Sheets("拉线图制作").Cells(Place1, 9)) + '米' + '</name>'+'\n')
        self.f2.write('<styleUrl>#cqt</styleUrl>'+'\n')
        self.f2.write('<Point>'+'\n')
        a = ThisWorkbook.Sheets("拉线图制作").Cells(Place1, 7)
        b = ThisWorkbook.Sheets("拉线图制作").Cells(Place1, 8)
        c = a + "," + b + ",0 "
        self.f2.write('<coordinates>' + c + '</coordinates>'+'\n')
        self.f2.write('</Point>'+'\n')
        self.f2.write('\n')
        a = ""
        b = ""
        c = ""

    def MakePlacemark2(self,Place2):
        self.f2.write('<Placemark>'+'\n')
        self.f2.write('<name><![CDATA[" + ThisWorkbook.Sheets("拉线图制作").Cells(Place2, 1) + "]]></name>'+'\n')
        self.f2.write('<styleUrl>#mycat</styleUrl>'+'\n')
        self.f2.write('<Point>'+'\n')
        a = ThisWorkbook.Sheets("拉线图制作").Cells(Place2, 2)
        b = ThisWorkbook.Sheets("拉线图制作").Cells(Place2, 3)
        c = a + "," + b + ",0 "
        self.f2.write('<coordinates>' + c + '</coordinates>'+'\n')
        self.f2.write('</Point>'+'\n')
        self.f2.write('\n')
        a = ""
        b = ""
        c = ""

    def MakeDescription1(self,Desc1):
        self.f2.write('<description>'+'\n')
        self.f2.write('<![CDATA['+'\n')
        self.f2.write('<table width="400" border="2">'+'\n')
        self.f2.write('<tr>'+'\n')
        self.f2.write('<td width="2%"><p align="middle">'+'\n')
        self.f2.write('<name>' + '测试点名' + '</name>'+'\n')
        self.f2.write('</td>'+'\n')
        self.f2.write('<td width="6%"><p align="middle">'+'\n')
        self.f2.write('<name>' + ThisWorkbook.Sheets("拉线图制作").Cells(Desc1, 6) + '</name>'+'\n')
        self.f2.write('</tr>'+'\n')
        self.f2.write('</table>'+'\n')
        self.f2.write('<p>'+'\n')
        self.f2.write('<a href="mailto:XXXX?subject=关于规划点与测试点图层的问题">联系作者(XXX)</a>'+'\n')
        self.f2.write('</p>'+'\n')
        self.f2.write(']]>'+'\n')
        self.f2.write('</description>'+'\n')
        self.f2.write('</Placemark>'+'\n')
        self.f2.write('\n')

    def MakeDescription2(self,Desc2):
        self.f2.write ('<description>'+'\n')
        self.f2.write ('<![CDATA['+'\n')
        self.f2.write ('<table width="400" border="2">'+'\n')
        self.f2.write ('<tr>'+'\n')
        self.f2.write ('<td width="2%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + '站名' + '</name>'+'\n')
        self.f2.write ('</td>'+'\n')
        self.f2.write ('<td width="6%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + ThisWorkbook.Sheets("拉线图制作").Cells(Desc2, 1) + '</name>'+'\n')
        self.f2.write ('</tr>'+'\n')
        self.f2.write ('<tr>'+'\n')
        self.f2.write ('<td width="2%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + '方位角' + '</name>'+'\n')
        self.f2.write ('</td>'+'\n')
        self.f2.write ('<td width="6%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + ThisWorkbook.Sheets("拉线图制作").Cells(Desc2, 4) + '</name>'+'\n')
        self.f2.write ("</tr>"+'\n')
        self.f2.write ('<tr>'+'\n')
        self.f2.write ('<td width="2%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + '经度' + '</name>'+'\n')
        self.f2.write ('</td>'+'\n')
        self.f2.write ('<td width="6%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + Str(ThisWorkbook.Sheets("拉线图制作").Cells(Desc2, 2)) + '</name>'+'\n')
        self.f2.write ('</tr>'+'\n')
        self.f2.write ('<tr>'+'\n')
        self.f2.write ('<td width="2%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + '纬度' + '</name>'+'\n')
        self.f2.write ('</td>'+'\n')
        self.f2.write ('<td width="6%"><p align="middle">'+'\n')
        self.f2.write ('<name>' + Str(ThisWorkbook.Sheets("拉线图制作").Cells(Desc2, 3).Value) + '</name>'+'\n')
        self.f2.write ('</tr>'+'\n')
        self.f2.write ('</table>'+'\n')
        self.f2.write ('<p>'+'\n')
        self.f2.write ('<a href="mailto:XXXX?subject=关于规划点与测试点图层的问题">联系作者(XXX)</a>'+'\n')
        self.f2.write ('</p>'+'\n')
        self.f2.write (']]>'+'\n')
        self.f2.write ('</description>'+'\n')
        self.f2.write ('</Placemark>'+'\n')
        self.f2.write ('\n')



    def MakeKML2(self):
        self.f2.write('<?xml version="1.0" encoding="utf-8"?>'+'\n')
        self.f2.write('<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">'+'\n')
        ##============================================写测试点========================================
        self.f2.write('<Document>'+'\n')
        self.f2.write('<name>规划站点与投诉</name>'+'\n')
        self.f2.write('<Folder>'+'\n')
        self.f2.write('<name>测试点</name>'+'\n')
        self.MakeFolder1()

        For Each SitName In ThisWorkbook.Sheets("拉线图制作").Range("f2:f" & ThisWorkbook.Sheets("拉线图制作").Cells(ThisWorkbook.Sheets("拉线图制作").Rows.Count, "f").End(xlUp).Row):
            if SitName is not None:
                Ts = SitName.Row
                self.MakePlacemark1(Ts)
                self.MakeDescription1(Ts)

        self.f2.write('</Folder>'+'\n')
        ##==============================================写规划点========================================
        self.f2.write('<Folder>'+'\n')
        self.f2.write('<name>规划点</name>'+'\n')
        self.MakeFolder3()
        For Each SitName In ThisWorkbook.Sheets("拉线图制作").Range("a2:a" & ThisWorkbook.Sheets("拉线图制作").Cells(ThisWorkbook.Sheets("拉线图制作").Rows.Count, 1).End(xlUp).Row):
            if SitName is not None:
                ro = Val(SitName.Row)
                self.MakePlacemark2(ro)
                self.MakeDescription2(ro)
        self.f2.write('</Folder>'+'\n')
        ##=============================================写拉线==============================================
        self.f2.write('<Folder>'+'\n')
        self.f2.write('<name>拉线</name>'+'\n')
        self.MakeFolder2()

        For Each SitName In ThisWorkbook.Sheets("拉线图制作").Range("a2:a" & ThisWorkbook.Sheets("拉线图制作").Cells(ThisWorkbook.Sheets("拉线图制作").Rows.Count, 1).End(xlUp).Row):
            if SitName is not None:
                self.f2.write('<Placemark>'+'\n')
                self.f2.write('<name>'+'\n')
                self.f2.write('<![CDATA[' + SitName.Value + ']]>'+'\n')
                self.f2.write('</name>'+'\n')
                self.f2.write('<styleUrl>#25516776960</styleUrl>'+'\n')
                self.f2.write('<LineString>'+'\n')
                self.f2.write('<coordinates>'+'\n')
                For Ts = SitName.Row To(SitName.Row + Val(ThisWorkbook.Sheets("拉线图制作").Cells(SitName.Row, 5).Value) - 1):
                    a = ThisWorkbook.Sheets("拉线图制作").Cells(Ts, 7)
                    b = ThisWorkbook.Sheets("拉线图制作").Cells(Ts, 8)
                    c = ThisWorkbook.Sheets("拉线图制作").Cells(SitName.Row, 2)
                    d = ThisWorkbook.Sheets("拉线图制作").Cells(SitName.Row, 3)
                    e = a + "," + b + ",0 " + c + "," + d
                    self.f2.write(e)
                    a = ""
                    b = ""
                    c = ""
                    d = ""
                    e = ""
                self.f2.write('</coordinates>'+'\n')
                self.f2.write('</LineString>'+'\n')
                self.f2.write('</Placemark>'+'\n')

        self.f2.write('</Folder>'+'\n')
        self.f2.write('</Document>'+'\n')
        self.f2.write('</kml>'+'\n')

        self.f2.close()
        print("生成完成！")

if __name__ == '__main__':
    tt = txt_tools(txt_file="拉线图.kml")
    # tt.MakeFolder1()
    tt.MakeKML2()

"""